import time
from selenium import webdriver
from selenium.webdriver.common.by import By


# 设置浏览器驱动
driver=webdriver.Chrome()
# 启动浏览器网址
driver.get('http://10.59.9.12:7001/')
# driver.maximize_window()
time.sleep(2)
# 点击登录
driver.find_element(By.XPATH,'//a[@href="/home/login.html"]').click()
time.sleep(2)
# 登录页面
dy1 = driver.find_element(By.CLASS_NAME,'reg-new').text
print(dy1)
time.sleep(2)
# 输入用户名
driver.find_element(By.NAME,'username').send_keys('123455556666')
time.sleep(2)
# 密码
driver.find_element(By.NAME,'password').send_keys('123456')
time.sleep(7)
# 点击登录
driver.find_element(By.CLASS_NAME,'finish-btn').click()
time.sleep(7)
# 积分
dy2 = driver.find_element(By.CLASS_NAME,'color-orage').text
dy21 = dy2.replace(' 积分','')
print(dy21)
time.sleep(2)
# 余额
dy3 = driver.find_element(By.CLASS_NAME,'color-black').text
dy31 = dy3.replace('¥ ','')
print(dy31)
time.sleep(5)
# 首页
driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/ul/li[1]/a').click()
time.sleep(2)
# 搜索
driver.find_element(By.CLASS_NAME,'search-input').send_keys('音乐耳机')
time.sleep(2)
# 点击搜索
driver.find_element(By.CLASS_NAME,'search-input-btn').click()
time.sleep(2)
# 点击商品
driver.find_element(By.XPATH,'//img[@class="lazy"]').click()
time.sleep(2)
# 商品名称
dy4 = driver.find_element(By.XPATH,'//*[@id="goodsForm"]/div/div[1]/span').text
print(dy4)
time.sleep(1)
# 单价
dy5 = driver.find_element(By.ID,'sell-price-box').text
print(dy5)
time.sleep(1)
# 数量
aa = driver.find_element(By.ID,'store_nums')
aa.clear()
aa.send_keys('2')
time.sleep(3)
# 加入购物车
driver.find_element(By.ID,'add-cart').click()
time.sleep(2)
# 点击购物车
driver.find_element(By.CLASS_NAME,'nav-settcart').click()
time.sleep(2)
# 勾选商品
driver.find_element(By.XPATH,'//*[@id="cart-box"]/div[1]/table/tbody/tr[2]/td[1]/input').click()
time.sleep(2)
# 点击立即结算
driver.find_element(By.CLASS_NAME,'ask-btn').click()
time.sleep(2)
# 地址
driver.find_element(By.ID,'address-831').click()
time.sleep(2)
# 数量
sl = driver.find_element(By.XPATH,'//*[@id="theForm"]/div[4]/div[1]/table/tbody/tr[2]/td[3]').text
print(sl)
# 运费
yf = driver.find_element(By.ID,'real-freight').text
yf1 = yf.replace('+','')
print(yf1)
time.sleep(2)
# 总价
zj = driver.find_element(By.ID,'order-amount').text
print(zj)
time.sleep(2)
assert float(dy5) * float(sl) + float(yf1) == float(zj)
# 下一步
driver.find_element(By.ID,'order-button').click()
time.sleep(2)
# 支付金额
# dy6 = driver.find_element(By.CLASS_NAME,'insignia-rmb').text
# print(6)
# time.sleep(2)
driver.quit()
